package com.wu.system.controller.wx;

import com.wu.common.page.PageResult;
import com.wu.common.query.PageQuery;
import com.wu.common.staticpack.Weixin;
import com.wu.common.utils.AjaxJson;
import com.wu.common.utils.Result;
import com.wu.common.utils.SystemTools;
import com.wu.common.utils.WeiXinHttpUtil;
import com.wu.dao.weixin.vo.WeixinGzUserVo;
import com.wu.dao.weixin.vo.WeixinNewsTemplateVo;
import com.wu.entity.weixin.po.MyJwWebJwid;
import com.wu.entity.weixin.po.WeixinGzuser;
import com.wu.entity.weixin.po.WeixinNewstemplate;
import com.wu.service.sys.query.WeixinNewsTemplateQuery;
import com.wu.service.weixin.service.WeixinNewstemplateService;
import io.swagger.v3.oas.annotations.Operation;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
* 描述：</b>图文模板表<br>
* @author weijian.zhang
* @since：2018年07月13日 12时46分13秒 星期五
* @version:1.0
*/
@RestController
@RequestMapping("/wx/weixinNewstemplate")
public class WeixinNewstemplateController{

   //图文预览接口
   private static String message_preview_url="https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN";

   public final static Logger log = LoggerFactory.getLogger(WeixinNewstemplateController.class);
   @Autowired
   private WeixinNewstemplateService weixinNewstemplateService;

/**
 * 列表页面
 * @return
 */
@GetMapping("page")
@Operation(summary = "分页")
@PreAuthorize("hasAuthority('sys:user:page')")
public Result<PageResult<WeixinNewsTemplateVo>> getList(@ModelAttribute WeixinNewsTemplateQuery query) throws Exception{
    PageResult<WeixinNewsTemplateVo> page = weixinNewstemplateService.queryPageList(query);
    return Result.ok(page);
}


//update-begin--Author:zhangweijian  Date: 20180802 for：上传图文素材到微信
    /**
     * 上传图文素材
     * @return
     */
    @RequestMapping(value="uploadNewstemplate",method = {RequestMethod.PUT, RequestMethod.POST})
    public Result uploadNewstemplate(@RequestBody  List<String> idList){
        try {
            String message=weixinNewstemplateService.uploadNewstemplate(idList.get(0),Weixin.weixinId);
            return Result.ok(message);
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.error("上传失败");
        }
    }

}

